<template>
  <div class="head">
    <div class="tit">
      <button class="tex1">新计泡统计报表</button>
    </div>
    <div class="line" />
    <el-row>
      <el-col :span="24">
        <div class="title1">
          <el-form
            ref="form"
            style="display: flex;flex-wrap: wrap;margin-top: 24px;justify-content: space-between;"
            :model="form"
            label-width="80px"
          >
            <div style="display: flex;justify-content: space-between;flex-wrap: wrap;width: 1564px;">
              <el-form-item class="text" label="网点名称">
                <el-select :disabled="true" class="input" placeholder="辽宁盘锦公司" style="width: 286px;">
                  <el-option label="辽宁盘锦公司" value="1" />
                </el-select>
              </el-form-item>
              <el-form-item class="text" label="承包区">
                <el-select
                  v-model="form.contractAreaNameId"
                  class="input"
                  placeholder="请选择"
                  style="width: 286px;"
                >
                  <el-option
                    v-for="item in ShowCoverAreaList"
                    :key="item.id"
                    :label="item.networkName"
                    :value="item.id"
                  />
                </el-select>
              </el-form-item>
              <el-form-item class="text" label="第一直属航空部" label-width="110px">
                <el-select v-model="form.transferCentreId" class="input" placeholder="请选择" style="width: 254px;">
                  <el-option
                    v-for="item in TransferCenterList"
                    :key="item.id"
                    :label="item.transferCenter"
                    :value="item.id"
                  />
                </el-select>
              </el-form-item>
              <!-- <el-form-item label="">
                <el-checkbox-group v-model="form.type">
                  <el-checkbox label="是否显示目的省份" name="type" />
                </el-checkbox-group>
              </el-form-item> -->
              <el-form-item class="text" label="日期汇总层级" label-width="100px">
                <el-select v-model="form.collectTime" class="input" placeholder="请选择" style="width: 254px;">
                  <el-option label="按天" value="1" />
                  <el-option label="按时间段" value="2" />
                </el-select>
              </el-form-item>
            </div>
            <div>
              <el-form-item>
                <el-button type="primary" @click="onSubmit">查询</el-button>
                <el-button @click="khClear">重置</el-button>
              </el-form-item>
            </div>
          </el-form>
        </div>
        <div class="title1">
          <el-form
            ref="form"
            style="display: flex;justify-content: space-between;flex-wrap: wrap;"
            :model="form"
            label-width="80px"
          >
            <div style="display: flex;justify-content: space-between;flex-wrap: wrap;width: 1070px;">
              <!-- <el-form-item class="text" label="目的省份">
                <el-select
                  v-model="mxForm.destinationProvince"
                  class="input"
                  placeholder="请选择目的省份"
                  style="width: 286px;"
                  @change="provinceChange"
                >
                  <el-option
                    v-for="item in ProvinceList"
                    :key="item.id"
                    :label="item.province"
                    :value="{ pid: item.pid, province: item.province }"
                  />
                </el-select>
              </el-form-item> -->
              <el-form-item class="text" label="统计类型">
                <el-select v-model="value1" class="input" placeholder="请选择" style="width: 286px;" @change="changeType">
                  <el-option label="预收+调整" value="1" />
                  <el-option label="按发件量统计" value="2" />
                </el-select>
              </el-form-item>
              <!-- <el-form-item class="text" label="重量是否为泡重" label-width="110px">
                <el-select v-model="form.isBubbleWeight" placeholder="请选择" style="width: 254px;">
                  <el-option v-for="item in cityList" :key="item.id" class="input" :label="item.city" :value="item.city" />
                </el-select>
              </el-form-item> -->
              <el-form-item class="text" label="汇总层级">
                <el-select v-model="form.collectType" class="input" placeholder="请选择" style="width: 286px;">
                  <el-option label="网点" value="1" />
                  <el-option label="承包区" value="2" />
                </el-select>
              </el-form-item>

              <div style="color: #EE3000;line-height: 40px;font-weight: 700;">7月1日起查询数据以该报表数值为准</div>
            </div>

            <div>
              <el-form-item>
                <el-button @click="onSubmit"><i class="el-icon-upload2" />导出</el-button>
              </el-form-item>
            </div>
          </el-form>
        </div>
        <div class="title1">
          <el-form
            ref="form"
            style="display: flex;flex-wrap: wrap;justify-content: space-between;"
            :model="form"
            label-width="80px"
          >
            <el-form-item class="text" label="日期">
              <el-date-picker
                v-model="value"
                type="daterange"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                value-format="yyyy-MM-dd"
                style="width: 690px"
                @change="changeTime"
              />
            </el-form-item>
          </el-form>
        </div>
        <el-table
          v-if="value1==='1'||value1===''"
          :key="Math.random()"
          :data="tableData"
          border
          max-height="734"
          :header-cell-style="{ background: '#f6f6f6' }"
          style="width: 100%"
        >
          <el-table-column type="index" :index="table_index" width="50" align="center" />
          <el-table-column prop="collectDate" label="时间段" width="180" align="center" />
          <el-table-column prop="networkNameId" label="网点编号" align="center" />
          <el-table-column prop="networkName.networkName" label="网点名称" align="center" />
          <el-table-column prop="hqTransferCentre.transferCode" width="120" label="直属航空部编码" align="center" />
          <el-table-column prop="hqTransferCentre.transferCenter" width="120" label="直属航空部名称" align="center" />
          <el-table-column label="预收" align="center">
            <el-table-column prop="preTicketNum" label="票件量" align="center" />
            <el-table-column prop="preNetWeight" label="实重" align="center" />
            <el-table-column prop="preNetWeightSettleAmount" width="110" label="实重结算金额" align="center" />
            <el-table-column prop="preBubbleWeight" label="计泡重" align="center" />
            <el-table-column prop="preBubbleOutWeight" label="泡出重" align="center" />
            <el-table-column prop="preBubbleOutSettleAmount" width="120" label="泡出重结算金额" align="center" />
            <el-table-column prop="preSettleWeight" label="结算重量" align="center" />
            <el-table-column prop="preSettleAmount" label="结算金额" align="center" />
          </el-table-column>
          <el-table-column label="调整" align="center">
            <el-table-column prop="adjustTicketNum" label="票件量" align="center" />
            <el-table-column prop="adjustActualWeight" label="实重" align="center" />
            <el-table-column prop="adjustActualWeightSettleAmount" width="140" label="实重调整结算金额" align="center" />
            <el-table-column prop="adjustBubbleWeight" label="计泡重" align="center" />
            <el-table-column prop="adjustBubbleOutWeight" label="泡出重" align="center" />
            <el-table-column prop="adjustBubbleOutWeightSettleAmount" width="120" label="泡出重调整金额" align="center" />
            <el-table-column prop="adjustSettleWeight" label="结算重量" align="center" />
            <el-table-column prop="adjustSettleAmount" label="调整金额" align="center" />
          </el-table-column>
        </el-table>
        <el-table
          v-if="value1==='2'"
          :data="tableData"
          border
          max-height="734"
          :header-cell-style="{ background: '#f6f6f6' }"
          style="width: 100%"
        >
          <el-table-column type="index" :index="table_index" width="50" align="center" />
          <el-table-column prop="collectDate" label="时间段" width="180" align="center" />
          <el-table-column prop="networkNameId" label="网点编号" align="center" />
          <el-table-column prop="networkName.networkName" label="网点名称" align="center" />
          <el-table-column prop="hqTransferCentre.transferCode" width="120" label="直属航空部编码" align="center" />
          <el-table-column prop="hqTransferCentre.transferCenter" width="120" label="直属航空部名称" align="center" />
          <el-table-column prop="ticketNum" label="票件量" align="center" />
          <el-table-column prop="settleWeight" label="结算重量" align="center" />
          <el-table-column prop="settleAmount" label="结算金额" align="center" />
          <el-table-column prop="bubbleWeight" label="计泡重" align="center" />
          <el-table-column prop="bubbleWeightSettleAmount" label="计泡重金额" align="center" />
          <el-table-column prop="netWeight" label="实重" align="center" />
          <el-table-column prop="netWeightSettleAmount" label="实重金额" align="center" />
          <el-table-column prop="bubbleOutWeight" label="泡出重" align="center" />
          <el-table-column prop="bubbleOutSettleAmount" label="泡出重金额" align="center" />
        </el-table>
        <div style="display: flex;justify-content: space-between;margin-top: 51px;">
          <div class="title2" />
          <div class="block" style="display: flex; justify-content: flex-end">
            <el-pagination
              background
              :current-page="current"
              :page-sizes="[10, 20, 30, 40]"
              :page-size="10"
              layout="total, prev, pager, next"
              :total="+total"
              prev-text="上一页"
              next-text="下一页"
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
            />
          </div>
        </div>

      </el-col>
    </el-row>
  </div>
</template>

<script>
import { ShowCoverAreaApi, TransferCenterApi, TransMeterBubbleApi, TransMeterBubbleApi1 } from '@/api/HqFinancePanel'
import { getProvinceList } from '@/api/dashboard'
export default {

  components: {},
  data() {
    return {
      value: '',
      value1: '',
      form: {
        collectTime: '',
        collectType: '',
        contractAreaNameId: '',
        endTime: '',
        isBubbleWeight: '',
        networkNameId: '1',
        pageDate: {
          pageNum: 1,
          pageSize: 10
        },
        startTime: '',
        transferCentreId: ''
      },
      mxForm: {
        destinationProvince: '',
        destinationCity: ''
      },
      tableData: [],
      ShowCoverAreaList: [], // 承包区列表
      TransferCenterList: [], // 第一直属航空部列表
      current: '', // 页数
      pages: '', // 条数
      total: '' // 总数

    }
  },

  computed: {},

  created() {
    this.getProvince()
    this.ShowCoverArea()
    this.TransferCenter()
  },

  methods: {
    // 序号
    table_index(index) {
      return (this.pages - 1) * this.current + index + 1
    },
    // 选择时间
    changeTime() {
      this.form.startTime = this.value[0]
      this.form.endTime = this.value[1]
    },
    // 上一页
    handleSizeChange(val) {
      this.form.pageDate.pageSize = val
      this.onSubmit()
    },
    // 下一页
    handleCurrentChange(val) {
      this.form.pageDate.pageNum = val
      this.onSubmit()
    },
    // 获取省
    getProvince() {
      getProvinceList().then((res) => {
        if (res.code === 200) {
          this.ProvinceList = res.data
        }
      })
    },
    // 承包区
    async ShowCoverArea() {
      const res = await ShowCoverAreaApi()
      this.ShowCoverAreaList = res.data
    },
    // 第一直属航空部
    async TransferCenter() {
      const res = await TransferCenterApi()
      this.TransferCenterList = res.data
    },
    table (res) {
      this.tableData = res.data.data
      this.total = res.data.total
      this.current = res.data.current
      this.pages = res.data.pages
    },
    // 查询
    async onSubmit() {
      if (this.value1 === '1') {
        const res = await TransMeterBubbleApi(this.form)
        this.table(res)
      } else if (this.value1 === '2') {
        const res = await TransMeterBubbleApi1(this.form)
        this.table(res)
      }
    },
    // 重置
    khClear() {
      Object.keys(this.form).forEach((key) => {
        if (key !== 'pageDate' && key !== 'networkNameId') {
          this.form[key] = ''
        }
      })
      this.tableData = []
      this.value = ''
      this.value1 = ''
      this.total = ''
      this.current = ''
      this.pages = ''
    },
    changeType() {
      this.tableData = []
    }
  }
}

</script>
<style  scoped lang="scss">
.tit {
  display: flex;
  .tex1 {
    margin-right: 48px;
    font-size: 16px;
    font-family: Source Han Sans CN;
    font-weight: 400;
    color: #666666;
    background: #fff;
    border: 1px #fff solid;
  }

  .active {
    font-family: Source Han Sans CN;
    font-weight: 700;
    color: #2087D0;
    position: relative;

  }

  .active::before {
    position: absolute;
    content: '';
    width: 110px;
    height: 2px;
    background: #2087D0;
    border-radius: 1px;
    bottom: -20px;
    left: 50%;
    transform: translate(-50%);
  }
}

.head {
  padding: 30px;
}

.title {
  font-size: 16px;
  font-family: Source Han Sans CN;
  font-weight: 400;
  color: #666666;
  margin-top: 20px;
}

.line {
  height: 1px;
  background: #D8D8D8;
  border-radius: 1px;
  margin-top: 19px;
}

.title1 {
   .text {
    font-size: 18px;
    font-family: Source Han Sans CN;
    font-weight: 400;
    color: #666666;

    .input {
      width: 286px;
      height: 36px;
      background: #FFFFFF;
      border-radius: 4px;
    }

    .input1 {
      width: 708px;
      height: 36px;
      background: #FFFFFF;
      border: 1px solid #B4B4B4;
      border-radius: 4px;
    }
  }
}

.title2 {
  font-size: 18px;
  font-family: Source Han Sans CN;
  font-weight: 400;
  color: #666666;
}
</style>
